﻿using System;
using System.Windows.Forms;

namespace BinaryToText
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void txtBinary_TextChanged(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;

            string[] myBits = txtBinary.Text.Split(new char[] { ' ' });

            foreach (string binaryStringBit in myBits)
            {
                try
                {
                    uint bit = Convert.ToUInt32(binaryStringBit, 2);
                    txtResult.Text += (char)bit;
                }
                catch (Exception)
                {
                    continue;
                }
            }
            txtText.Text = string.Empty;
        }

        private void txtText_TextChanged(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;

            string myText = txtText.Text;

            foreach (char myChar in myText)
            {
                txtResult.Text += Convert.ToString((int)myChar, 2) + " ";
            }
            txtBinary.Text = string.Empty;
        }
    }
}